package wechat

import (
	"gitee.com/small_fish_official_net/more_wechat/model/https"
	"github.com/PuerkitoBio/goquery"
	"github.com/astaxie/beego/logs"
	"strings"
)

func get_session(login_url string){
	// 登录完成，获取登录code
	html,err := https.Get(login_url+"&fun=new&version=v2")
	if err != nil {
		logs.Error("网络请求错误，原因："+err.Error())
		return
	}
	// 使用goquery进行获取返回的xml信息
	dom,err:=goquery.NewDocumentFromReader(strings.NewReader(html))
	if err != nil {
		logs.Error("元素匹配错误，原因："+err.Error())
	}
	if dom.Find("error ret").Text() == "1203" {
		logs.Error("抱歉，您没有权限登录")
		logs.Error(dom.Find("error message").Text())
		return
	}
	if dom.Find("error ret").Text() != "0" {
		logs.Error("未知错误")
		logs.Error(dom.Find("error message").Text())
		return
	}
	// 登录成功，输出相关信息
	logs.Info("ret:",dom.Find("error ret").Text())
	logs.Info("message:",dom.Find("error message").Text())
	logs.Info("skey:",dom.Find("error skey").Text())
	logs.Info("wxsid:",dom.Find("error wxsid").Text())
	logs.Info("wxuin:",dom.Find("error wxuin").Text())
	logs.Info("pass_ticket:",dom.Find("error pass_ticket").Text())
	logs.Info("isgrayscale:",dom.Find("error isgrayscale").Text())
	logs.Info("")
	logs.Info("以下为Cookie信息")
	for _,v := range https.Cookies {
		logs.Info(v.Name,v.Value)
	}
}